// components/switch/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    activeValue: {
      type: null,
      value: true
    },
    inactiveValue: {
      type: null,
      value: false
    },
    activeText: {
      type: String,
      value: ''
    },
    inactiveText: {
      type: String,
      value: ''
    },
    switchValue: {
      type: Boolean,
      value: false
    },
    nodeText: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    // switchValue: false,
    switchText: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClick () {
      const { activeValue, inactiveValue, inactiveText, activeText } = this.properties;
      console.log(this.data.switchValue);
      const checked = this.data.switchValue === activeValue;
      const value = checked ? inactiveValue : activeValue;
      const text = checked ? activeText : inactiveText;
      this.setData({
        switchValue: value,
        switchText: text
      });
      this.triggerEvent('change', checked)
    },
    switchTo(value,valueText){
      this.setData({
        switchValue: value,
        switchText: valueText
      });
    }
  }
});
